package ro.msg.quiz.dao;

import java.sql.SQLException;

//AUTHOR: Ervin

public class RelationQuizzAndQuestionsDB {

    public static void createRelation(int quizId, int questionID) throws ClassNotFoundException, SQLException {
	String sql = "INSERT into relations (idQuiz , idQuestion) values ('" + quizId + "' , '" + questionID + "')";
	DatabaseCon.getInstance().executeUpdate(sql);
    }

    public static void createRelation(String quizName, String[] questions) throws ClassNotFoundException, SQLException {
	int numberOfQueries = questions.length;
	String sql[] = new String[numberOfQueries];

	int quizId = 0;
	quizId = QuizDB.getQuizID(quizName);

	for (int i = 0; i < numberOfQueries; i++) {
	    int questionId = 0;
	    questionId = QuestionDB.getQuestionId(questions[i]);

	    sql[i] = "INSERT into relations (idQuiz,idQuestion) values ('" + quizId + "' , '" + questionId + "')";
	}
	DatabaseCon.getInstance().executeBatch(sql);
    }
}
